package com.xindz.cn.mvptest.components.product.view;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.avos.avoscloud.AVException;
import com.blankj.utilcode.util.ToastUtils;
import com.xindz.cn.mvptest.R;
import com.xindz.cn.mvptest.base.LoadBaseActivity;
import com.xindz.cn.mvptest.components.product.data.ProductBean;
import com.xindz.cn.mvptest.components.product.persenter.ProductShowPersenter;
import com.xindz.cn.mvptest.shared.core.loadsir.callback.ErrorCallback;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @name MvpTest
 * @class name：com.xindz.cn.mvptest.components.product.view
 * @describe describe
 * @anthor XINDZ
 * @time 2017/10/31 13:26
 * @change
 * @chang time
 * @class describe
 */
public class ProductShowActivity extends LoadBaseActivity<ProductShowView, ProductShowPersenter> implements ProductShowView<ProductBean, AVException> {


    @BindView(R.id.rv_product_show)
    RecyclerView rvProductShow;
    private List<ProductBean> mList = new ArrayList<>();
    private ProductShowAdapter adapter;

    @Override
    protected String getContentTitle() {
        return "商品展示";
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_product_show;
    }

    @Override
    protected void initView() {
        rvProductShow.setLayoutManager(new LinearLayoutManager(this));
        adapter = new ProductShowAdapter(this, mList);
        rvProductShow.setAdapter(adapter);

    }

    @Override
    protected void initData() {
        getPresneter().showProduct();
    }

    @Override
    protected void initNet() {

    }

    @Override
    protected void onNetReload(View v) {

    }

    @Override
    public ProductShowPersenter createPresneter() {
        return new ProductShowPersenter();
    }

    @Override
    public ProductShowView createView() {
        return this;
    }


    @Override
    public void loadData(List<ProductBean> l, AVException e) {
        if (e == null && l != null) {
            ToastUtils.showShort("请求成功");
            mBaseLoadService.showSuccess();
            mList = l;
            adapter.setmList(mList);
        } else {
            mBaseLoadService.showCallback(ErrorCallback.class);
        }
    }
}
